// TOWN SCRIPT
//    Town 12: Stone Circle

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,choice;
short lead_char;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered

 i = 0;
 while (i < 5) {
  if (char_ok(i)) {
   lead_char = i;
   i = 5;
  }
  else
   i = i + 1;
 }

set_crime_tolerance(1);

force_instant_terrain_redraw();
if (get_sdf(4,16) == 0) {
 set_flag(4,16,1);
 message_dialog("You find yourself in a bizarre and completely unfamiliar place with walls consisting of alien machinery. The air is very stale and dry. No scent or sounds are apparent. You have no idea where you are.","");
}

break;

beginstate EXIT_STATE;

set_flag(4,15,0);

break;

beginstate START_STATE;

break;


beginstate 10;

message_dialog("These runes radiate a forcefield. You cannot continue down this passage.","");
block_entry(1);

break;


beginstate 11;

if (get_sdf(4,17) == 0) {
 set_flag(4,17,1);
 message_dialog("This room may have been a lab. There is a pentagram on the floor with lab-like equipment all around. You notice a crystal container in the corner. Unfortunately, this is too alien to know what this room is for.","");
}

break;


beginstate 12;

if (get_sdf(4,18) == 0) {
 set_flag(4,18,1);
 message_dialog("The narrow, cramped passageway opens up into a much wider chamber filled with all sorts of weird contraptions. You have no idea what anything here does.","");
}

break;


beginstate 13;

if (get_sdf(4,19) == 0) {
 set_flag(4,19,1);
 message_dialog("If you had to guess the function of this room, you would say that it was used for the manufacture of crystals. It seems like the process was interrupted mid-way through as a crystal sits in the middle of formation.","You compare this to three other crystals on pedestals that are much better formed. You notice those crystals emit a weak glow.");
}

break;


beginstate 14;

if (get_sdf(4,20) == 0) {
 set_flag(4,20,1);
 message_dialog("This crystal does not appear to be fully formed. It is much smaller and misshapen compared to the other crystals. It also lacks the dim light the others posess.","There is a lot of machinery here to fabricate these devices, but you do not even know where to begin operating them.");
}

break;


beginstate 15;

if (get_sdf(4,21) == 0) {
 set_flag(4,21,1);
 message_dialog("Finally you encounter something you understand. This was a meeting room of some sort. Chances are the operators of this station met here to discuss and do whatever those operators did, whatever they were.","");
}

break;


beginstate 16;

if (get_sdf(4,22) == 0) {
 set_flag(4,22,1);
 message_dialog("This room looks very important. A large image is suspended in the middle of the room. It looks like a sphere with large bumps and troughs. You immediately recognize them as the continents of Ermarian!","The image is a globe of the world. You notice another much smaller sphere orbiting around it. Is this the moon or something else? Might that dot represent you? If so, that would mean you are above the sky!");
}

break;


beginstate 17;

reset_dialog();
 add_dialog_str(0,"These controls are incredibly complicated. You touch a few of them and they zap back with a light forcefield. They have been shielded with defense mechanisms to keep people like you away from them.",0);
 add_dialog_str(1,"However, one of them is a button that flashes red. You put your hand close and feel no forcefield. You could push it if you wanted.",0);
 add_dialog_choice(0,"Push the button.");
 add_dialog_choice(1,"Leave it alone.");
 choice = run_dialog(1);
 if (choice == 1) {
  message_dialog("You press the button. A voice rings out. _Running disaster simulation._ You turn around to the globe, the small orbiting dot traces a line. You notice each orbit is lower than the previous.","Eventually the dot crashes into the ocean near one of the continents, Aizo, you believe. _Projected time remaining to correct: 7.3 planetary revolutions._ Unfortunately, you don't know how to fix the problem.");
  if (party_has_trait(4) == 1)
   message_dialog("Using your good education, you know a planetary revolution is a year. The simulator measures time in planetary rotations or days. The simulator has recorded 852,227 days since activation.","Given that there are 280 days in a year, this station must be over 3000 years old! And here you are, up in the sky. You still have no idea what beings could possibly create something so magical. Fascinating.");
 }

break;


beginstate 18;

if (get_sdf(4,23) == 0) {
reset_dialog();
 add_dialog_str(0,"A crystal glows dimly here. For some reason, you have the urge to touch the crystal. It could be quite risky.",0);
 add_dialog_choice(0,"Touch the crystal.");
 add_dialog_choice(1,"Leave it alone.");
 choice = run_dialog(1);
 if (choice == 1) {
  if (run_select_a_pc(0) == 0)
   end();
  else {
   award_party_xp(300,5);
   set_flag(4,23,1);
   message_dialog("You touch the crystal and it glows brightly. A strange vibration fills the air and your minds twist and warp. It is not painful, very disorienting. When everything goes back to normal, you feel strangely smarter.","The crystal grows dim and then all light fades out of it altogether. This must have been only meant to be used once.");
  }
 }
}
else
 message_dialog("The crystal is dark and contains no energy. It has been used up already.","");

break;


beginstate 19;

if (get_sdf(4,24) == 0) {
reset_dialog();
 add_dialog_str(0,"A crystal glows dimly here. For some reason, you have the urge to touch the crystal. It could be quite risky.",0);
 add_dialog_choice(0,"Touch the crystal.");
 add_dialog_choice(1,"Leave it alone.");
 choice = run_dialog(1);
 if (choice == 1) {
  if (run_select_a_pc(0) == 0)
   end();
  else {
   alter_stat(get_selected_pc(),26,1);
   set_flag(4,24,1);
   message_dialog("You touch the crystal and it glows brightly. A surge of energy flows into you, knocking you back. You rise up and you feel a strange aura that you cannot describe around you.","The crystal grows dim and then all light fades out of it altogether. This must have been only meant to be used once.");
  }
 }
}
else
 message_dialog("The crystal is dark and contains no energy. It has been used up already.","");

break;


beginstate 20;

if (get_sdf(4,25) == 0) {
reset_dialog();
 add_dialog_str(0,"A crystal glows dimly here. You notice that the crystal has a small crack in it. For some reason, you have the urge to touch the crystal. It could be quite risky.",0);
 add_dialog_choice(0,"Touch the crystal.");
 add_dialog_choice(1,"Leave it alone.");
 choice = run_dialog(1);
 if (choice == 1) {
  if (run_select_a_pc(0) == 0)
   end();
  else {
   damage_char(get_selected_pc(),60,3);
   set_flag(4,25,1);
   message_dialog("You touch the crystal and it glows brightly. An intense surge of electrical energy flows into you, causing severe harm. You are thrown back in pain.","The crystal grows dim and then all light fades out of it altogether. This must have been only meant to be used once.");
  }
 }
}
else
 message_dialog("The crystal is dark and contains no energy. It has been used up already.","");

break;


beginstate 21;

 reset_dialog();
 add_dialog_str(0,"A teleporter here. Hopefully it will take you back.",0);
 add_dialog_choice(0,"Enter the portal.");
 add_dialog_choice(1,"Stay away.");
 choice = run_dialog(1);
 if (choice == 1)
  set_state_continue(22);
 else
  block_entry(1);

break;


beginstate 22;

i = 0;
while (i < 6) {
 put_boom_on_char(i,2,0);
 i = i + 1;
}
force_instant_terrain_redraw();
run_animation_sound(10);
move_to_new_town(12,16,20);

break;